import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";

function getNewLogin(item) {
    return getDeptBindContent(item)
}

export default function getDeptBindContent(item) {
    console.log(item)
    let roles = null;
    let token = localStorage.getItem("token")

    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
                'Authorization': token
        },
        url: url.api_url+`DeptBindRole/GetDeptBindContent`,
        type: 'post',
        contentType:"application/json",
        data:JSON.stringify({
             DEPT_ID:item
        }),
        success: function (result) {
            if(result.result=="Token過期請重新登錄") {
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                roles = getNewLogin(item)
            }else {
                roles = {
                    bindRoleIdList:result.result
                }
            }
             // localStorage.set("deptBindContent",JSON.stringify(result.result))
        },
        error:function (error) {
            message.error("请求异常")
        }
    })
    return roles;

//  写ajax时把上面注释取消
//
//     localStorage.setItem('deptBindContent',JSON.stringify([1,2,3,4,5]))
//     return(
//         {
//             bindRoleIdList:[1,2,3,4,5]
//         }
//     )
}

